package com.yuven.baselib.utils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 正则匹配
 */
public class RegexUtil {

    //手机号
    public static final String REG_PHONE = "^1[3-9]\\d{9}$";
    //邮箱号
    public static final String REG_EMIL = "^[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,6}$";
    //数字、字母、特殊符号
    public static final String REG_MIX_PWD = "^(?=.*\\d)(?=.*[a-zA-Z])(?=.*[`~!@#$%^&*()_\\-+=<>?:\"|,.\\/;'\\\\\\·~！@#￥%……&*（）——\\-+=|《》？：“”、；‘'，。、{}【】])[\\da-zA-Z`~!@#$%^&*()_\\-+=<>?:\"|,.\\/;'\\\\\\·~！@#￥%……&*（）——\\-+=|《》？：“”、；‘'，。、{}【】]{8,}$";

    public static boolean checkEmail(String emailStr) {
        Pattern pattern = Pattern.compile(REG_EMIL, Pattern.CASE_INSENSITIVE);
        Matcher matcher = pattern.matcher(emailStr);
        return matcher.find();
    }

    public static boolean checkPhone(String phone) {
        return Pattern.matches(REG_PHONE,phone);
    }

    /**
     * 数字 + 字母 + 特殊字符
     * @param password
     * @return
     */
    public static boolean checkMixPassword(String password) {
        if (password.matches(REG_MIX_PWD)) {
            return true;
        }
        return false;
    }
}
